package mall

import (
	"context"
	"fmt"
	"private-domain-overseas-service/admin/business/api/internal/repository/mall"
	"private-domain-overseas-service/pkg/xerr"
	"private-domain-overseas-service/tools/ent"
	"time"

	"private-domain-overseas-service/admin/business/api/internal/svc"
	"private-domain-overseas-service/admin/business/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type MallSiteDeleteLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// NewMallSiteDeleteLogic - 删除站点
func NewMallSiteDeleteLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MallSiteDeleteLogic {
	return &MallSiteDeleteLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *MallSiteDeleteLogic) MallSiteDelete(req *types.MallSiteDelete) error {
	// 创建实例
	mallSiteDao := mall.NewMallSiteDao(l.ctx, l.svcCtx)

	// 组装参数
	mallSiteInfo := &ent.HzMallSite{
		ID:       int(req.Id),
		DeleteAt: time.Now().Unix(),
	}

	// 删除站点
	err := mallSiteDao.MallSiteDelete(mallSiteInfo, nil)
	if err != nil {
		return xerr.ErrCodeMsg(xerr.ServerOperationExceptionError, fmt.Sprintf("删除站点失败：%s", err.Error()))
	}

	return nil
}
